package File;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;

@WebServlet("/upload")
// 上传文件必备的注解
@MultipartConfig
public class upLoad extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Part part = req.getPart("myfile");// 与input标签中的file属性相呼应
        System.out.println("文件名: "+ part.getSubmittedFileName());
        System.out.println("文件大小: "+ part.getSize());
        System.out.println("文件类型: "+ part.getContentType());
        // 写入的文件位置
        part.write("D:/test/1.png");
    }
}
